type Employee struct {
   Id int
   Importance int
   subIds []int
}

// DFS 前序遍历
func getImportance1(employees []*Employee, id int) int {
    var idEmpMap = make(map[int]*Employee)
    for _, e := range employees {
        idEmpMap[e.Id] = e
    }

    var res = 0

    var preOrder func(int)
    preOrder = func(id int) {
        var emp = idEmpMap[id]
        if emp == nil {
            return
        }

        res += emp.Importance

        for _, child := range emp.subIds {
            preOrder(child)
        }
    }

    preOrder(id)

    return res
}


// DFS 后序遍历
func getImportance2(employees []*Employee, id int) int {
    var idEmpMap = make(map[int]*Employee)
    for _, e := range employees {
        idEmpMap[e.Id] = e
    }

    var postOrder func(int) int
    postOrder = func(id int) int {
        var emp = idEmpMap[id]
        if emp == nil {
            return 0
        }

        var total = 0
        for _, child := range emp.subIds {
            total += postOrder(child)
        }

        return emp.Importance + total
    }

    return postOrder(id)
}